package com.urea.web.controller.urea;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.urea.system.domain.vo.FleetTerminalVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.urea.common.annotation.Log;
import com.urea.common.core.controller.BaseController;
import com.urea.common.core.domain.AjaxResult;
import com.urea.common.enums.BusinessType;
import com.urea.system.domain.FleetTerminal;
import com.urea.system.service.IFleetTerminalService;
import com.urea.common.utils.poi.ExcelUtil;
import com.urea.common.core.page.TableDataInfo;

/**
 * 车队绑定的终端Controller
 * 
 * @author liuzd
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/fleet/terminal")
@Api(tags = "车队终端绑定信息")
public class FleetTerminalController extends BaseController
{
    @Autowired
    private IFleetTerminalService fleetTerminalService;

    /**
     * 查询车队绑定的终端列表
     */
    @PreAuthorize("@ss.hasPermi('fleet:terminal:list')")
    @GetMapping("/list")
    public TableDataInfo list(FleetTerminal fleetTerminal)
    {
        startPage();
        List<FleetTerminal> list = fleetTerminalService.selectFleetTerminalList(fleetTerminal);
        return getDataTable(list);
    }

    /**
     * 导出车队绑定的终端列表
     */
    @PreAuthorize("@ss.hasPermi('fleet:terminal:export')")
    @Log(title = "车队绑定的终端", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FleetTerminal fleetTerminal)
    {
        List<FleetTerminal> list = fleetTerminalService.selectFleetTerminalList(fleetTerminal);
        ExcelUtil<FleetTerminal> util = new ExcelUtil<FleetTerminal>(FleetTerminal.class);
        util.exportExcel(response, list, "车队绑定的终端数据");
    }

    /**
     * 获取车队绑定的终端详细信息
     */
    @PreAuthorize("@ss.hasPermi('fleet:terminal:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fleetTerminalService.selectFleetTerminalById(id));
    }

    /**
     * 新增车队绑定的终端
     */
//    @PreAuthorize("@ss.hasPermi('fleet:terminal:add')")
    @Log(title = "车队绑定的终端", businessType = BusinessType.INSERT)
    @PostMapping("/bind")
    @ApiOperation("车队绑定的终端")
    public AjaxResult add(@RequestBody FleetTerminalVo vo)
    {
        fleetTerminalService.insertFleetTerminal(vo);
        return success();
    }

    /**
     * 修改车队绑定的终端
     */
    @PreAuthorize("@ss.hasPermi('fleet:terminal:edit')")
    @Log(title = "车队绑定的终端", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FleetTerminal fleetTerminal)
    {
        return toAjax(fleetTerminalService.updateFleetTerminal(fleetTerminal));
    }

    /**
     * 删除车队绑定的终端
     */
    @PreAuthorize("@ss.hasPermi('fleet:terminal:remove')")
    @Log(title = "车队绑定的终端", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fleetTerminalService.deleteFleetTerminalByIds(ids));
    }
}
